package ${PACKAGE_NAME}.controller;

import ${PACKAGE_NAME}.core.dto.IdDto;
import ${PACKAGE_NAME}.core.page.QueryCondition;
import ${PACKAGE_NAME}.dto.${ENTITY_NAME}SaveDto;
import ${PACKAGE_NAME}.converter.${ENTITY_NAME}Converter;
import ${PACKAGE_NAME}.service.${ENTITY_NAME}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 *
 * </p>
 *
 * @author ${USER}
 * @since ${DATE} ${TIME}
 */
@RestController
@RequestMapping("/${ROUTE_PATH}")
public class ${ENTITY_NAME}Controller {

    @Autowired
    private ${ENTITY_NAME}Service ${ENTITY_NAME_LOWER}Service;

    @PostMapping("/save")
    public Object save(@RequestBody @Valid ${ENTITY_NAME}SaveDto dto) {
        return ${ENTITY_NAME_LOWER}Service.save(${ENTITY_NAME}Converter.INSTANCE.to${ENTITY_NAME}(dto));
    }

    @PostMapping("/deleteById")
    public Object deleteById(@RequestBody @Valid IdDto dto) {
        ${ENTITY_NAME_LOWER}Service.deleteById(dto.getId());
        return true;
    }

    @PostMapping("/deleteAll")
    public Object deleteAll() {
        ${ENTITY_NAME_LOWER}Service.deleteAll();
        return true;
    }

    @PostMapping("/findById")
    public Object findById(@RequestBody @Valid IdDto dto) {
        return ${ENTITY_NAME_LOWER}Service.findById(dto.getId());
    }

    @PostMapping("/findAll")
    public Object findAll() {
        return ${ENTITY_NAME_LOWER}Service.findAll();
    }

    @PostMapping("/findPage")
    public Object findPage(@RequestBody @Valid QueryCondition condition) {
        return ${ENTITY_NAME_LOWER}Service.findPage(condition);
    }
}